import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

public class Lesson11 {

    private static AtomicInteger atomicInteger = new AtomicInteger(1);

    private static ExecutorService executorService = new ThreadPoolExecutor(10, 10, 1, TimeUnit.HOURS, new ArrayBlockingQueue(10), r -> {
        Thread thread = new Thread(r);
        thread.setDaemon(true);
        thread.setName("custom-executor-" + atomicInteger.incrementAndGet());
        return thread;
    });

    /**
     *  这个例子演示了依赖的CompletableFuture如果等待两个阶段完成后执行了一个Runnable。
     *  注意下面所有的阶段都是同步执行的，第一个阶段执行大写转换，第二个阶段执行小写转换。
     *
     * */
    public static void main(String[] args) {

        String message = "Message";

        CompletableFuture completableFuture = CompletableFuture
                .completedFuture(message)
                .thenApply(String::toUpperCase)
                .runAfterBoth(CompletableFuture.completedFuture(message).thenApply(String::toLowerCase), () -> {
                    System.out.println("二阶段已执行完成");
                });
    }
}
